package org.example.nt.ssl;


import java.io.ByteArrayInputStream;
import java.security.PrivateKey;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;

public class GM implements ICryptoProvider4GM{
    private int err = 0;
    public static PkiGMListener listener = null;

    public static void setGM(PkiGMListener listener) {
        GM.listener = listener;
    }

    public GM() {
    }

    public int getError() {
        return this.err;
    }

    public X509Certificate getCert(boolean var1) {
        if (GMJCEConf.gmDebug) {
            System.out.println("getCert sig=" + var1);
        }

        Object var2 = null;

        byte[] data;
        try {
            Class clazz = GM.class;
            synchronized(GM.class) {
                data = listener.getCert(var1);
                if (GMJCEConf.gmDebug) {
                    System.out.println("GM: sig=" + var1 + ",getCrt=" + data);
                }
            }
            CertificateFactory cert = CertificateFactory.getInstance("X509");
            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(data);
            X509Certificate certificate = (X509Certificate)cert.generateCertificate(byteArrayInputStream);
            return certificate;
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }


    }

    public PrivateKey getPrivateKey(boolean var1) {
        return null;
    }

    public byte[] doSign(byte[] var1, int var2, int var3) {
        if (GMJCEConf.gmDebug) {
            System.out.println("doSign...offset=" + var2 + ",length=" + var3);
        }

        try {
            Class var4 = GM.class;
            synchronized(GM.class) {
                byte[] var5 = listener.doSign(var1, var2, var3);
                if (GMJCEConf.gmDebug) {
                    System.out.println("GM: sign=" + var5);
                }

                return var5;
            }
        } catch (Exception var7) {
            var7.printStackTrace();
            throw var7;
        }
    }
}
